<?php
/**
 * Created by PhpStorm.
 * User: t
 * Date: 2024/3/25
 * Time: 18:47
 */

namespace app\merchant\controller;

use app\admin\model\StaffRole;
use app\home\model\AmountLog;
use app\home\model\GoodsOrder;
use app\home\model\PackageOrder;
use app\home\model\User;

use app\merchant\model\PackageUseLog;
use app\Request;


class Home
{

    public function index(Request $request)
    {
        $goodsOrderModel = new GoodsOrder();
        $param = $request->param();
        $orderTurnover = $goodsOrderModel
            ->where('create_time', '>=', strtotime($param['start_time']))
            ->where('create_time', '<=', strtotime($param['end_time']))
            ->where('status', '=', 6)
            ->sum('reality_amount'); // 营业额
        $orderWaitPay = $goodsOrderModel// 待支付
        ->where('create_time', '>=', strtotime($param['start_time']))
            ->where('create_time', '<=', strtotime($param['end_time']))
            ->where('status', '=', 1)
            ->sum('reality_amount'); // 营业额
        $orderEndCount = $goodsOrderModel// 订单数量
        ->where('create_time', '>=', strtotime($param['start_time']))
            ->where('create_time', '<=', strtotime($param['end_time']))
            ->where('status', '=', 6)
            ->sum('number'); // 营业额
        $orderTotalCount = $goodsOrderModel// 订单数量
        ->where('create_time', '>=', strtotime($param['start_time']))
            ->where('create_time', '<=', strtotime($param['end_time']))
            ->sum('number');
        $orderPayCount = $goodsOrderModel//
        ->where('create_time', '>=', strtotime($param['start_time']))
            ->where('create_time', '<=', strtotime($param['end_time']))
            ->where('status', '=', 1)
            ->sum('number'); // 营业额
        $ordershouCount = $goodsOrderModel//
        ->where('create_time', '>=', strtotime($param['start_time']))
            ->where('create_time', '<=', strtotime($param['end_time']))
            ->where('status', '=', 4)
            ->sum('number'); // 营业额
        $userModel = new User();
        $userCount = $userModel
            ->where('create_time', '>=', strtotime($param['start_time']))
            ->where('create_time', '<=', strtotime($param['end_time']))
            ->count();
        $goodsModel = new \app\merchant\model\Goods();
        $goodsCount = $goodsModel
            ->where('create_time', '>=', strtotime($param['start_time']))
            ->where('create_time', '<=', strtotime($param['end_time']))
            ->where(['status' => 1])
            ->count();
        $packageModel = new \app\home\model\Package();
        $packageCount = $packageModel
            ->where('create_time', '>=', strtotime($param['start_time']))
            ->where('create_time', '<=', strtotime($param['end_time']))
            ->where(['status' => 1])
            ->count();
        $packageOrderModel = new PackageOrder();
        $packageOrderCount = $packageOrderModel
            ->where('create_time', '>=', strtotime($param['start_time']))
            ->where('create_time', '<=', strtotime($param['end_time']))
            ->where(['status' => 3])
            ->count();
        $packageOrderAmount = $packageOrderModel
            ->where('create_time', '>=', strtotime($param['start_time']))
            ->where('create_time', '<=', strtotime($param['end_time']))
            ->where(['status' => 3])
            ->sum('price'); // 营业额
        $staffRoleModel = new StaffRole();
        $staffCount = $staffRoleModel->where('store_id', '>', 0)->group('staff_id')->count();
        $data = [
            'orderTurnover' => $orderTurnover,
            'orderWaitPay' => $orderWaitPay,
            'orderTotalCount' => $orderTotalCount,
            'orderEndCount' => $orderEndCount,
            'orderPayCount' => $orderPayCount,
            'ordershouCount' => $ordershouCount,
            'userCount' => $userCount,
            'goodsCount' => $goodsCount,
            'packageCount' => $packageCount,
            'packageOrderCount' => $packageOrderCount,
            'packageOrderAmount' => $packageOrderAmount,
            'staffCount' => $staffCount,

        ];
        return success('', $data);
    }

    public function rechargeStatistics(Request $request)
    {
        $param = $request->param();
        $amountLogModel = new AmountLog();
        $zaixianTotal = 0;
        $xianxiaTotal = 0;
        $shaomaTotal= 0;
        $shaomaWhere = [['pay_type','=',1],
            ['operate_type','in',[6,7]]
        ];
        $xianxiaWhere = [['pay_type','=',2],
            ['operate_type','in',[2,3,4,5]]
        ];
        $zaixianWhere = [['pay_type','=',3],
            ['operate_type','=',1]
        ];

        if ($param['type'] == '1') {  // 充值
            $field  ="sum(amount) as  amount,date_format(from_unixtime(create_time), '%Y-%m-%d %H:00:00') as dateTime";
            for ($i = 0; $i <= 6; $i++) {
                $zaixianAmount[$i] = $xianxiaAmount[$i] = $shaomaAmount[$i] = ['amount' => 0, 'datetime' => $i * 4,];
            }

        } else {
            $field  ="sum(amount) as  amount,date_format(from_unixtime(create_time), '%Y-%m-%d') as dateTime";
            $diff = strtotime($param['end_time']) - strtotime($param['start_time']);
            $days_diff = ceil($diff / (60 * 60 * 24)); // 60秒 * 60分钟 * 24小时 = 1天
            for ($i = 0; $i <= $days_diff; $i++) {
                $key = date('Y-m-d', strtotime($param['start_time']) + (60 * 60 * 24 * $i));
                $zaixianAmount[$key] = ['amount' => 0, 'datetime' => $key];
                $shaomaAmount[$key] = ['amount' => 0, 'datetime' => $key];
                $xianxiaAmount[$key] = ['amount' => 0, 'datetime' => $key];
            }
        }
        $group = 'dateTime';
        $shaomaData = $amountLogModel->byTimeStatistics($shaomaWhere,$field,$group);
        $xianxiaData = $amountLogModel->byTimeStatistics($xianxiaWhere,$field,$group);
        $zaixianData = $amountLogModel->byTimeStatistics($zaixianWhere,$field,$group);
        if ($param['type'] == '1') {
            foreach ($zaixianData as $value) {

                if (date('H', strtotime($value['dateTime'])) / 4 > 0) {
                    $zaixianAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['amount'] =
                        bcadd($value['amount'], $zaixianAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['amount'], 2);
                }
                $zaixianTotal = bcadd($value['amount'], $zaixianTotal, 2);
            }
            foreach ($shaomaData as $value) {
                if (date('H', strtotime($value['dateTime'])) / 4 > 0) {
                    $shaomaAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['amount'] =
                        bcadd($value['amount'], $shaomaAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['amount'], 2);
                }
                $shaomaTotal = bcadd($value['amount'], $shaomaTotal, 2);
            }
            foreach ($xianxiaData as $value) {
                if (date('H', strtotime($value['dateTime'])) / 4 > 0) {
                    $xianxiaAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['amount'] =
                        bcadd($value['amount'], $xianxiaAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['amount'], 2);
                }
                $xianxiaTotal = bcadd($value['amount'], $xianxiaTotal, 2);
            }
        }else{
            foreach ($zaixianData as $value) {
                if (date('H', strtotime($value['dateTime'])) / 4 > 0) {
                    $zaixianAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['amount'] =
                        bcadd($value['amount'], $zaixianAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['amount'], 2);
                }
                $zaixianTotal = bcadd($value['amount'], $zaixianTotal, 2);
            }
            foreach ($shaomaData as $value) {
                if (date('H', strtotime($value['dateTime'])) / 4 > 0) {
                    $shaomaAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['amount'] =
                        bcadd($value['amount'], $shaomaAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['amount'], 2);
                }
                $shaomaTotal = bcadd($value['amount'], $shaomaTotal, 2);
            }
            foreach ($xianxiaData as $value) {
                if (date('H', strtotime($value['dateTime'])) / 4 > 0) {
                    $xianxiaAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['amount'] =
                        bcadd($value['amount'], $xianxiaAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['amount'], 2);
                }
                $xianxiaTotal = bcadd($value['amount'], $xianxiaTotal, 2);
            }
        }
        $data['zaixian'] = array_values($zaixianAmount);   // k 线 在线支付
        $data['xianshang'] = array_values($shaomaAmount); // k 线 线上支付
        $data['xianxia'] = array_values($xianxiaAmount); // k 线 线下支付
        $data['zaixianAmount'] = $zaixianTotal; // 统计金额
        $data['xianxiaAmount'] = $xianxiaTotal;// 统计金额
        $data['xianshangAmount'] = $shaomaTotal;// 统计金额
        $totalRecharge = $amountLogModel->where('operate_type','in', [1,2,3,4,5,6,7])
           ->sum('amount');
        $recharge = $amountLogModel->where('operate_type','in', [1,2,3,4,5,6,7])
            ->where('create_time', '>=', strtotime($param['start_time']))
            ->where('create_time', '<=', strtotime($param['end_time']))->sum('amount');
        $data['recharge_count'] = $amountLogModel->where('operate_type','in', [1,2,3,4,5,6,7])->count();
        $data['total_recharge'] = $totalRecharge; // 累计充值统计
        $data['recharge'] = $recharge;   //  筛选统计\
        $goodsOrderModel = new GoodsOrder();
        $goodsxianxiaConsumption = $goodsOrderModel->where('pay_way','in',[3,4,5,6])->where(['status' => 6])->sum('reality_amount');
        $PackageOrderModel = new PackageOrder();
        $packagexianxiaConsumption = $PackageOrderModel->where('pay_type','in',[3,4,5,6])->where(['status' => 3])->sum('price');
        $data['xianxia_consumption']  = bcadd($goodsxianxiaConsumption,$packagexianxiaConsumption,2);

        $goodsConsumptionAmount = 0;
        $packageConsumptionAmount = 0;
        if ($param['consumption_type'] == 1) {
            for ($i = 0; $i <= 6; $i++) {
                $goodsConsumptionData[$i] = $packageConsumptionData[$i] = ['amount' => 0, 'datetime' => $i * 4,];
            }
            $goodsConsumption = $goodsOrderModel->field("sum(reality_amount) as amount,date_format(from_unixtime(create_time), '%Y-%m-%d %H:00:00') as dateTime")
                ->where('create_time', '>=', strtotime($param['consumption_start_time']))
                ->where('create_time', '<=', strtotime($param['consumption_end_time']))
                ->where(['status' => 6 ])
                ->group("dateTime")->select()->toArray();
            $packageOrderModel = new PackageOrder();
            $packageConsumption = $packageOrderModel->field("sum(price) as amount,date_format(from_unixtime(create_time), '%Y-%m-%d %H:00:00') as dateTime")
                ->where('create_time', '>=', strtotime($param['consumption_start_time']))
                ->where('create_time', '<=', strtotime($param['consumption_end_time']))
                ->where(['status' => 3])
                ->group("dateTime")->select()->toArray();
            foreach ($goodsConsumption as $value) {
                if (date('H', strtotime($value['dateTime'])) / 4 > 0) {
                    $goodsConsumptionData[ceil(date('H', strtotime($value['dateTime'])) / 4)]['amount'] = bcadd($value['amount'], $goodsConsumptionData[ceil(date('H', strtotime($value['dateTime'])) / 4)]['amount'],2);}
                    $goodsConsumptionAmount = bcadd($value['amount'],$goodsConsumptionAmount,2);
            }
            foreach ($packageConsumption as $packageValue) {
                if (date('H', strtotime($value['dateTime'])) / 4 > 0) {
                    $packageConsumptionData[ceil(date('H', strtotime($value['dateTime'])) / 4)]['amount']
                        = bcadd($packageValue['amount'], $packageConsumptionData[ceil(date('H', strtotime($value['dateTime'])) / 4)]['amount'],2); ;
                }
                $packageConsumptionAmount  =bcadd($packageValue['amount'],$packageConsumptionAmount,2); ;
            }
        } else {
            $diff = strtotime($param['consumption_end_time']) - strtotime($param['consumption_start_time']);
            $days_diff = ceil($diff / (60 * 60 * 24)); // 60秒 * 60分钟 * 24小时 = 1天
            for ($i = 0; $i < $days_diff; $i++) {
                $key = date('Y-m-d', strtotime($param['consumption_start_time']) + (60 * 60 * 24 * $i));
                $goodsConsumptionData[$key] = $packageConsumptionData[$key] = ['amount' => 0, 'datetime' => date('m-d', strtotime($param['consumption_start_time']) + (60 * 60 * 24 * $i))];
            }
            $goodsOrderModel = new GoodsOrder();
            $goodsConsumption = $goodsOrderModel->field("sum(reality_amount) as amount,date_format(from_unixtime(create_time), '%Y-%m-%d') as dateTime")
                ->where('create_time', '>=', strtotime($param['consumption_start_time']))
                ->where('create_time', '<=', strtotime($param['consumption_end_time']))
                ->where(['status' => 6])
                ->group("dateTime")->select()->toArray();
            $packageOrderModel = new PackageOrder();
            $packageConsumption = $packageOrderModel->field("sum(price) as amount,date_format(from_unixtime(create_time), '%Y-%m-%d') as dateTime")
                ->where('create_time', '>=', strtotime($param['consumption_start_time']))
                ->where('create_time', '<=', strtotime($param['consumption_start_time']))
                ->where(['status' => 1])
                ->group("dateTime")->select()->toArray();
            foreach ($goodsConsumption as $value) {
                if (array_key_exists($value['dateTime'], $goodsConsumptionData)) {
                        $goodsConsumptionData[$value['dateTime']]['amount'] =  bcadd($value['amount'],  $goodsConsumptionData[$value['dateTime']]['amount'],2);
                    }
                    $goodsConsumptionAmount = bcadd($value['amount'],$goodsConsumptionAmount,2);
            }
            foreach ($packageConsumption as $value) {
                if (array_key_exists($value['dateTime'], $packageConsumptionData)) {
                    $packageConsumptionData[$value['dateTime']]['amount'] = bcadd($value['amount'],   $packageConsumptionData[$value['dateTime']]['amount'],2);
                }
                $packageConsumptionAmount = bcadd($value['amount'],$packageConsumptionAmount,2);
            }
        }
        $data['goods_consumption_amount'] = $goodsConsumptionAmount;
        $data['package_consumption_amount'] = $packageConsumptionAmount;
        $data['goods_consumption_data'] = array_values($goodsConsumptionData);
        $data['package_consumption_data'] = array_values($packageConsumptionData);
        $userModel = new User();
        $data['total_user_count'] = $userModel->count('id');
        $firstDayMonth = strtotime(date('Y-m-01 00:00:00'));
        $data['month_user_count'] = $userModel->where('create_time', '>=', $firstDayMonth)->count('id');
        $today = strtotime(date('Y-m-d 00:00:00'));
        $data['today_user_count'] = $userModel->where('create_time', '>=', $today)->count('id');
        if ($param['uesr_type'] == 1) {
            for ($i = 0; $i <= 6; $i++) {
                $userCount[$i] = ['count' => 0, 'datetime' => $i * 4,];
            }
            $userData = $userModel->field("count(id) as count,date_format(from_unixtime(create_time), '%Y-%m-%d %H:00:00') as dateTime")
                ->where('create_time', '>=', strtotime($param['user_start_time']))
                ->where('create_time', '<=', strtotime($param['user_end_time']))
                ->group("dateTime")->select()->toArray();
            foreach ($userData as $value) {
                if (date('H', strtotime($value['dateTime'])) / 4 > 0) {
                    $userCount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['count'] = $value['count'];
                }
            }
        } else {
            $diff = strtotime($param['user_end_time']) - strtotime($param['user_start_time']);
            $days_diff = ceil($diff / (60 * 60 * 24)); // 60秒 * 60分钟 * 24小时 = 1天
            for ($i = 0; $i < $days_diff; $i++) {
                $key = date('Y-m-d', strtotime($param['user_start_time']) + (60 * 60 * 24 * $i));
                $userCount[$key] = ['count' => 0, 'datetime' => date('m-d', strtotime($param['user_start_time']) + (60 * 60 * 24 * $i))];
            }
            $userData = $userModel->field("count(id) as count,date_format(from_unixtime(create_time), '%Y-%m-%d') as dateTime")
                ->where('create_time', '>=', strtotime($param['user_start_time']))
                ->where('create_time', '<=', strtotime($param['user_end_time']))
                ->group("dateTime")->select()->toArray();

            foreach ($userData as $value) {
                if (array_key_exists($value['dateTime'], $userCount)) {
                    $userCount[$value['dateTime']]['count'] = $value['count'];
                }
            }
        }
        $balance = $userModel->sum('balance');
        $data['balance'] = $balance;
        $data['user_count'] = array_values($userCount);
        $firstDayMonth = strtotime(date('Y-m-01 00:00:00'));
        $data['month_goods_amount'] = $goodsOrderModel->where(['status' => 6])->where('create_time', '>=', $firstDayMonth)
            ->sum('reality_amount');
        return success('列表', $data);
    }

    public function statistics(Request $request){
        $param = $request->param();
        $start_time = strtotime($param['start_time']);
        $userModel = new \app\home\model\User();

        $goodsOrderModel = new GoodsOrder();
        $where= [];
        if ( $request->staff_account['role_type'] == 3){
            $where['store_id'] = $request->staff_account['store_id'];
        }elseif ($request->staff_account['role_type'] == 2) {
            $where['staff_id'] = $request->staff_account['id'];

        }
        $data['balance'] =   $userModel->sum('balance');
        $goods_order_number =   $goodsOrderModel->where('create_time','>',$start_time)->where($where)->where(['status' => 6])->count();
        $packageOrderModel = new PackageOrder();
        $package_order_number =   $packageOrderModel->where('create_time','>',$start_time)->where($where)->where(['status' => 3])->count();
        $amountModel = new AmountLog();
        $data['consumption_amount'] =   $amountModel->where($where)
            ->where('status','=',1)
            ->where('operate_type' ,'in' ,[8,9,10,11,12,13,14,15,16,17,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35])->sum('amount');;

        $data['order_count'] = $goods_order_number +$package_order_number ;
        return success('统计', $data);
    }

    public function staffStatistics(Request $request){
        $packageUseLog = new PackageUseLog();
        $amountModel = new AmountLog();
       if ( $request->staff_account['role_type'] == 3){
           $packageUseCount = $packageUseLog
               ->where(['store_id' => $request->staff_account['store_id']])
               ->count();
           $rechargeAmount = $amountModel
               ->where(['store_id' => $request->staff_account['store_id']])
               ->where('operate_type','in', [2,3,4,5,6,7])
               ->sum('amount');
           $packageAmount = $amountModel
               ->where(['store_id' => $request->staff_account['store_id']])
               ->where('operate_type','in', [11,12,13,14,15,16,17])
               ->sum('amount');
           $consumptionAmount = $amountModel
               ->where(['store_id' => $request->staff_account['store_id']])
               ->where('operate_type','in', [8,9,10,11,12,13,14,15,16,17,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35])
               ->sum('amount');

       }elseif ($request->staff_account['role_type'] == 2){

           $packageUseCount =  $packageUseLog
               ->where(['staff_id' => $request->staff_account['id']])
               ->count();
           $rechargeAmount = $amountModel
               ->where(['staff_id' => $request->staff_account['id']])
               ->where('operate_type','in', [2,3,4,5,6,7])
               ->sum('amount');
           $packageAmount = $amountModel
               ->where(['staff_id' => $request->staff_account['id']])
               ->where('operate_type','in', [11,12,13,14,15,16,17])
               ->sum('amount');
           $consumptionAmount = $amountModel
               ->where(['staff_id' => $request->staff_account['id']])
               ->where('operate_type','in', [8,9,10,11,12,13,14,15,16,17,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35])
               ->sum('amount');

       }

        $polymerizationWechat = $amountModel
            ->where(['store_id' => $request->staff_account['store_id']])
            ->where('operate_type','=', 29)
            ->sum('amount');
        $polymerizationAli = $amountModel
            ->where(['store_id' => $request->staff_account['store_id']])
            ->where('operate_type','=', 28)
            ->sum('amount');
       return success('统计',[
           'package_use_count' => $packageUseCount,
           'recharge_amount' => $rechargeAmount,
           'package_amount' => $packageAmount,
           'consumption_amount' => $consumptionAmount,
           'polymerization_wechat' => $polymerizationWechat,
           'polymerization_ali' => $polymerizationAli,
       ]);

    }

    public function packageUseLog(Request $request){
        $param = $request->param();
        $where = [];
        if ( $request->staff_account['role_type'] == 3){
            $where['store_id'] = $request->staff_account['store_id'];
        }elseif ($request->staff_account['role_type'] == 2) {
            $where['staff_id'] = $request->staff_account['id'];
        }
        $packageUseLogModel = new PackageUseLog();
        if ($param['type'] == 1) {
            for ($i = 0; $i <= 6; $i++) {
                $packageData[$i] = ['count' => 0, 'datetime' => $i * 4,];
            }
            $packageUseLog = $packageUseLogModel->field("count(id) as count,date_format(from_unixtime(create_time), '%Y-%m-%d %H:00:00') as dateTime")
                ->where('create_time', '>=', strtotime($param['start_time']))
                ->where('create_time', '<=', strtotime($param['end_time']))
                ->group("dateTime")->select()->toArray();
            foreach ($packageUseLog  as $value){
                if (date('H', strtotime($value['dateTime'])) / 4 > 0) {
                    $packageData[ceil(date('H', strtotime($value['dateTime'])) / 4)]['count'] = $value['count'];
                }
            }
        }else{
            $diff = strtotime($param['end_time']) - strtotime($param['start_time']);
            $days_diff = ceil($diff / (60 * 60 * 24)); // 60秒 * 60分钟 * 24小时 = 1天
            for ($i = 0; $i < $days_diff; $i++) {
                $key = date('Y-m-d', strtotime($param['start_time']) + (60 * 60 * 24 * $i));
                $packageData[$key] = ['count' => 0, 'datetime' => date('m-d', strtotime($param['start_time']) + (60 * 60 * 24 * $i))];
            }
            $packageUseLog = $packageUseLogModel->field("count(id) as count,date_format(from_unixtime(create_time), '%Y-%m-%d') as dateTime")
                ->where('create_time', '>=', strtotime($param['start_time']))
                ->where('create_time', '<=', strtotime($param['end_time']))
                ->group("dateTime")->select()->toArray();

            foreach ($packageUseLog  as $value){
                if (array_key_exists($value['dateTime'], $packageData)) {
                    $packageData[$value['dateTime']]['count'] = $value['count'];
                }
            }
            $packageData  = array_values($packageData);
        }
        $data['today_package_log'] = $packageUseLogModel->where($where)->where('create_time','>',strtotime(date('Y-m-01')))->count();
        $data['month_package_log'] = $packageUseLogModel->where($where)->where('create_time','>',strtotime(date('Y-m-d')))->count();
        $data['total_package_log'] = $packageUseLogModel->where($where)->count();
        $data['package_data'] = $packageData;
        $data['package_data'] = $packageData;
         $data['package_data'] = $packageData;
        return success('核销',$data);


    }

    public function consumptionStatistics(Request $request){
        $param = $request->param();
        $where = [];
        if ( $request->staff_account['role_type'] == 3){
            $where['store_id'] = $request->staff_account['store_id'];
        }elseif ($request->staff_account['role_type'] == 2) {
            $where['staff_id'] = $request->staff_account['id'];
        }
        $amountLogModel = new AmountLog();
        if ($param['type'] == 1) {
            for ($i = 0; $i <= 6; $i++) {
                $amountLogData[$i] = ['count' => 0, 'datetime' => $i * 4,];
            }
            $amountData = $amountLogModel->field("sum(amount) as amount,date_format(from_unixtime(create_time), '%Y-%m-%d %H:00:00') as dateTime")
                ->where('create_time', '>=', strtotime($param['start_time']))
                ->where('create_time', '<=', strtotime($param['end_time']))
                ->where('operate_type','in', [1,2,3,4,5,6,7,8,10,12,13,14,15,16,17,22,23,24,25,26,27,28,29,30,31,32,33,34,35])
                ->group("dateTime")->select()->toArray();
            foreach ($amountData  as $value){
                if (date('H', strtotime($value['dateTime'])) / 4 > 0) {
                    $amountLogData[ceil(date('H', strtotime($value['dateTime'])) / 4)]['amount'] = $value['amount'];
                }
            }

        }else{
            $diff = strtotime($param['user_end_time']) - strtotime($param['start_time']);
            $days_diff = ceil($diff / (60 * 60 * 24)); // 60秒 * 60分钟 * 24小时 = 1天
            for ($i = 0; $i < $days_diff; $i++) {
                $key = date('Y-m-d', strtotime($param['start_time']) + (60 * 60 * 24 * $i));
                $amountLogData[$key] = ['count' => 0, 'datetime' => date('m-d', strtotime($param['start_time']) + (60 * 60 * 24 * $i))];
            }
            $amountData = $amountLogModel->field("sum(amount) as amount,date_format(from_unixtime(create_time), '%Y-%m-%d ') as dateTime")
                ->where('create_time', '>=', strtotime($param['start_time']))
                ->where('create_time', '<=', strtotime($param['end_time']))
                ->where('operate_type','in', [1,2,3,4,5,6,7,8,10,12,13,14,15,16,17,22,23,24,25,26,27,28,29,30,31,32,33])
                ->group("dateTime")->select()->toArray();
            foreach ($amountData  as $value){
                if (array_key_exists($value['dateTime'], $amountData)) {
                    $amountLogData[$value['dateTime']]['count'] = $value['count'];
                }
            }
            $amountLogData = array_values($amountLogData);
        }

        $data['amount_data'] = $amountLogData;
        return success('消费', $data);
    }


}